package com.occludens.admin.ui;

import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;

import com.googlecode.objectify.annotation.Cache;
import com.googlecode.objectify.annotation.Index;
import com.googlecode.objectify.annotation.Subclass;
import com.occludens.admin.AdminObject;

@Subclass(index=true)
@Cache
public abstract class AdminObjectUI extends AdminObject {
	@Index private String label = "";
	@Index private Map<String,String> settings = new HashMap<String,String>();
	
	protected AdminObjectUI() {} // Mandatory for Objectify
	
	public AdminObjectUI(String name) {
		super(name);
	}
	
	public String getLabel() {
    	return this.label;
    }
    
    public void setLabel(String label) {
    	this.label = label;
    }
	
	public Map<String,String> getSettings() {		
		return this.settings;
	}
	
	public void setSettings(Map<String,String> settings) {
		if (settings==null) {
			settings = new HashMap<String,String>();
		}
		Iterator<String> settingsKeySetItr = settings.keySet().iterator();
		while (settingsKeySetItr.hasNext()) {
			String settingKey = settingsKeySetItr.next();
			String settingValue = settings.get(settingKey);
			if (this.settings.containsKey(settingKey)) {
				this.settings.remove(settingKey);
			}
			this.settings.put(settingKey, settingValue);
		}//End of while settingsKeySetItr
		this.settings = settings;
	}
	
	public void addSetting(String settingKey, String settingValue) {
		if (this.settings.containsKey(settingKey)) {
			this.settings.remove(settingKey);
		}
		this.settings.put(settingKey, settingValue);
	}
	
	public void removeSetting(String settingKey) {
		if (this.settings.containsKey(settingKey)) {
			this.settings.remove(settingKey);
		}
	}

}
